package clinic.ms.service;

import clinic.ms.entity.Home;
import clinic.ms.mapper.HomeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

@Service
public class HomeService {

    @Autowired
    HomeMapper homeMapper;

    public void insertHome(Home home) {
        // 根据日期生成家庭病房编号
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String formatDate = format.format(date);
        System.out.println(formatDate);
        home.setHomeNo(formatDate);
        homeMapper.insertHome(home);

    }

    public ArrayList<Home> queryByNoAndName(String homeNo, String homeName) {
        return homeMapper.queryByNoAndName(homeNo,homeName);
    }

    public boolean deleteByNo(String homeNo) {
        return homeMapper.deleteByNo(homeNo) == 1;
    }

    public boolean updateByNo(Home home) {
        return homeMapper.updateByNo(home) == 1;
    }

    public Home queryByNo(String homeNo) {
        return homeMapper.queryByNo(homeNo);
    }
}
